/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;

/**
 *
 * @author James
 */
@Entity
@Inheritance(strategy=InheritanceType.JOINED)
public class TCubeAccount implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private String  username;
    private String  password;
    private String  IC;
    private String  firstName;
    private String  lastName;
    private String  gender;
    private String  address1;
    private String  address2;
    private String  postalCode;
    private String  countryCode;
    private String  phone;
    private String  email;
    private String  country;
    private String  city;
    private String  timezone;
    private boolean active;
    private boolean activated;
    private int     accountLevel;
    private long    birthday;
    private long    registeredDate;
    @ManyToMany
    private List<TCubePrivilege> listOfPrivileges;
    
    public TCubeAccount() {
        this.address1           = "";
        this.address2           = "";
        this.postalCode         = "";
        this.timezone           = "";
        this.active             = true; //TODO: check if account is active before allowing login
        this.activated          = false;
        this.registeredDate     = System.currentTimeMillis();
        this.listOfPrivileges   = new ArrayList<TCubePrivilege>();
    }
    
    public void createTCubeAccount(String username, String password, String IC, String firstName, String lastName, String gender, String countryCode, String phone, String email, String country, String city, int accountLevel) {
        this.username         = username;
        this.password         = password;
        this.IC               = IC;
        this.firstName        = firstName;
        this.lastName         = lastName;
        this.gender           = gender;
        this.countryCode      = countryCode;
        this.phone            = phone;
        this.email            = email;
        this.country          = country;
        this.city             = city;
        this.accountLevel     = accountLevel;
    }
    
    //Getters and Setters
    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getIC() {
        return IC;
    }

    public void setIC(String IC) {
        this.IC = IC;
    }

    public int getAccountLevel() {
        return accountLevel;
    }

    public void setAccountLevel(int accountLevel) {
        this.accountLevel = accountLevel;
    }

    public boolean isActivated() {
        return activated;
    }

    public void setActivated(boolean activated) {
        this.activated = activated;
    }

    public boolean isActive() {
        return active;
    }

    public void setActive(boolean active) {
        this.active = active;
    }

    public String getAddress1() {
        return address1;
    }

    public void setAddress1(String address1) {
        this.address1 = address1;
    }

    public String getAddress2() {
        return address2;
    }

    public void setAddress2(String address2) {
        this.address2 = address2;
    }

    public long getBirthday() {
        return birthday;
    }

    public void setBirthday(long birthday) {
        this.birthday = birthday;
    }

    public String getCity() {
        return city;
    }

    public void setCity(String city) {
        this.city = city;
    }

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }

    public String getCountryCode() {
        return countryCode;
    }

    public void setCountryCode(String countryCode) {
        this.countryCode = countryCode;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    public String getGender() {
        return gender;
    }

    public void setGender(String gender) {
        this.gender = gender;
    }

    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public long getRegisteredDate() {
        return registeredDate;
    }

    public void setRegisteredDate(long registeredDate) {
        this.registeredDate = registeredDate;
    }

    public String getTimezone() {
        return timezone;
    }

    public void setTimezone(String timezone) {
        this.timezone = timezone;
    }

    public String getPostalCode() {
        return postalCode;
    }

    public void setPostalCode(String postalCode) {
        this.postalCode = postalCode;
    }

   public List<TCubePrivilege> getListOfPrivileges() {
        return listOfPrivileges;
    }

    public void setListOfPrivileges(List<TCubePrivilege> listOfPrivileges) {
        this.listOfPrivileges = listOfPrivileges;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (username != null ? username.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof TCubeAccount)) {
            return false;
        }
        TCubeAccount other = (TCubeAccount) object;
        if ((this.username == null && other.username != null) || (this.username != null && !this.username.equals(other.username))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.TCubeAccount[ id=" + username + " ]";
    }
    
}
